<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('邮件复核') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true" @submit.native.prevent>
      <el-form-item :label="$t('基金名称')" prop="fundName">
        <el-input
          v-model="queryParams.fundName"
          :placeholder="$t('基金名称')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="lpBulletinInvestorList" border>
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('公告标题')" align="center" prop="title" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <el-link class="link-a" type="primary" :underline="false" @click="updateHandle(scope.row)">{{ scope.row.title }}</el-link>
        </template>
      </el-table-column>
      <el-table-column :label="$t('基金名称')" align="center" prop="fundName" show-overflow-tooltip />
      <el-table-column :label="$t('公告类型')" align="center" prop="type" width="120" :formatter="fundTypeFormat" show-overflow-tooltip />
      <el-table-column :label="$t('状态')" align="center" prop="status" width="120" show-overflow-tooltip>
        <template slot-scope="scope">
          <span :style="{ color: (scope.row.status === '已发送' ? '#48bd4a' : '') }">{{ formatStatus(scope.row.status) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="120">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['lp:LpPublicBulletin:edit']"
            size="small"
            type="text"
            icon="el-icon-link"
            @click="updateHandle(scope.row)"
          >{{ $t('复核') }}</el-button>
          <el-button
            v-if="scope.row.status !== '已发送'"
            v-hasPermi="['lp:LpPublicBulletin:edit']"
            size="small"
            type="text"
            icon="el-icon-refresh-left"
            @click="turnDown(scope.row)"
          >{{ $t('驳回') }}</el-button>
          <el-button
            v-if="scope.row.status === '已发送'"
            v-hasPermi="['lp:LpPublicBulletin:edit']"
            size="small"
            type="text"
            icon="el-icon-refresh-left"
            @click="deleteHandle(scope.row)"
          >{{ $t('删除') }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改公示公告-出资人对话框 -->
    <el-dialog :title="$t(title)" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" :destroy-on-close="true" :show-close="false" custom-class="dialogForm" append-to-body>
      <EmailReviewForm v-if="formOpen" ref="emailReviewForm" />
    </el-dialog>
  </div>
</template>

<script>
import { delLpPublicBulletin, findListNotReviewed, updateReviewStatus } from '@/api/fund/lpBase/lp/affiche/affiche.js'
import EmailReviewForm from '@/views/fund/lpBase/lp/EmailReviewForm.vue'
import { listLpAnnouncementTemplate } from '@/api/fund/lpBase/lp/affiche/afficheListTemplate'
export default {
  components: {
    EmailReviewForm
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 公示公告-出资人表格数据
      lpBulletinInvestorList: [],
      // 弹出层标题
      title: this.$t('公示公告'),
      // 是否显示弹出层
      formOpen: false,
      // 查询参数
      queryParams: {
        fundName: '',
        pageNum: 1,
        pageSize: 10
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      lpTemplate: []
    }
  },
  created() {
    // 获取公告类型
    listLpAnnouncementTemplate().then(response => {
      response.rows.forEach(item => {
        this.lpTemplate.push({ dictValue: item.id, dictLabel: item.name })
      })
    })
    this.getList()
  },
  methods: {
    /** 查询公示公告-出资人列表 */
    getList() {
      this.loading = true
      findListNotReviewed(this.queryParams).then(response => {
        this.lpBulletinInvestorList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 类型字典回显
    fundTypeFormat(row) {
      return this.selectDictLabel(this.lpTemplate, row.type)
    },
    // 格式化状态
    formatStatus(status) {
      if (status === undefined || status === '' || status === null) {
        return this.$t('未复核')
      } else {
        return this.$t(status)
      }
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        parentId: undefined,
        lpId: undefined,
        lpEmail: undefined,
        lpPhone: undefined,
        level: undefined,
        subscribedAmount: undefined,
        callMoney: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        delFlag: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.queryHandle()
    },
    /** 复核按钮操作 */
    updateHandle(row) {
      this.formOpen = true
      this.$nextTick(() => {
        // 调用form页面的 init 方法初始化数据
        this.$refs.emailReviewForm.init(row)
      })
    },
    /**
     * 删除
     * @param row
     */
    deleteHandle(row) {
      debugger
      var _this = this
      this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        type: 'warning'
      }).then(function() {
        _this.loading = true
        delLpPublicBulletin(row.id).then(() => {
          _this.getList()
          _this.msgSuccess(_this.$t('删除成功'))
        })
      }).then(() => {
      }).catch(function() {
        _this.loading = false
      })
    },
    // 驳回
    turnDown(row) {
      this.loading = true
      updateReviewStatus(row.id, '已驳回').then(response => {
        this.msgInfo(this.$t(response.msg))
        if (response.code === 200) {
          this.getList()
        } else {
          this.loading = false
        }
      })
    }
  }
}
</script>
